package com.fiveflavors.suittar.gui.inputpanel;

import java.awt.event.KeyEvent;

import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

public class SuittarTextArea extends JTextArea {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6584769722039261917L;

	@Override
	protected void processKeyEvent(KeyEvent e) {

		super.processKeyEvent(e);

		if (e.getKeyCode() == KeyEvent.VK_ENTER) {
			Document doc = getDocument();
			try {
				while (doc.getText(doc.getStartPosition().getOffset(), doc.getLength()).indexOf("\n") > -1) {
					String text = doc.getText(doc.getStartPosition().getOffset(), doc.getLength());
					doc.remove(text.indexOf("\n"), 1);
				}
			}
			catch(BadLocationException ex) {
				ex.printStackTrace();
			}
		}
		
	}
	
	@Override
	public String getText() {
		return super.getText().replaceAll("\n", "");
	}
	
}
